package com.example.big_orange2.service;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.big_orange2.common.Result;
import com.example.big_orange2.entity.notice;
import com.example.big_orange2.entity.pagedata_n;
import com.example.big_orange2.mapper.noticeMapper;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;

import javax.annotation.Resource;

@Service
public class NoticeService {

    @Resource
    noticeMapper noticeMapper;

    public Result<?> findPage(Integer page, Integer limit, String s){
        pagedata_n ru=new pagedata_n();
        LambdaQueryWrapper<notice> wrapper = Wrappers.<notice>lambdaQuery();
        if(StrUtil.isNotBlank(s)){//判断search不是空
            wrapper.like(com.example.big_orange2.entity.notice::getNoticeid,Integer.parseInt(s));

        }
//        System.out.print("pagenum:"+page+";pageSize:"+limit);
//        int pageNum=page;
//        int pageSize=limit;
        Page<notice> ClientPage=noticeMapper.selectPage(new Page<>(page,limit),wrapper);
        //?是泛型，表示任意类型;pageNum:前台第几页；pageSize：前台每页多少条数据；search：前台要搜索的内容;defaltvalue:默认值
        //new Page<>(pageNum,pageSize);     MybatisPlusConfig提供的分页对象。
        //Client::四个点可以直接访问对象的属性; like模糊查询;
//        System.out.println(ClientPage.getRecords());//分页内容
//        System.out.println(ClientPage.getTotal());//总条数
        ru.setNotices(ClientPage);
        ru.setTotal(ClientPage.getTotal());
        return  Result.success(ru);//返回结果

    }
}
